package com.dj.xbirdie.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.dj.xbirdie.R
import com.dj.xbirdie.entity.HistoryEntity

public class HistoryListAdapter(
    var list: MutableList<HistoryEntity>
) : RecyclerView.Adapter<HistoryListAdapter.MyViewHolder>(){
    //    lateinit var ctx:onTopicEventInterface?;
    class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view)

    // Create new views (invoked by the layout manager)
    override fun onCreateViewHolder(parent: ViewGroup,
                                    viewType: Int): HistoryListAdapter.MyViewHolder {
        println("创建")

        val textView = LayoutInflater.from(parent.context).inflate(R.layout.message_history_list, parent, false);
        return MyViewHolder(textView)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        println("渲染")
        holder.view.findViewById<TextView>(R.id.historyMsgNum).text = list[position].num.toString();
        holder.view.findViewById<TextView>(R.id.historyTime).text=list[position].date.toLocaleString();
        holder.view.findViewById<TextView>(R.id.historyTopicName).text = list[position].topic
        holder.view.findViewById<TextView>(R.id.historyPayload).text=list[position].message.toString()

        holder.view.findViewById<TextView>(R.id.historyQos).text=list[position].message.qos.toString()
        holder.view.findViewById<TextView>(R.id.historyRetain).text=list[position].message.isRetained.toString()
        holder.view.findViewById<TextView>(R.id.historyDuplicate).text=list[position].message.isDuplicate.toString()

    }

    override fun getItemCount() = list.size
//    override fun subject(topic: String?) {
//        ctx.subject(topic)
//    }
//
//    override fun unSubject(topic: String?) {
//        ctx.unSubject(topic);
//    }
//
//    fun onTopicEventInterface(ctx: onTopicEventInterface) {
//        this.ctx=ctx;
//    }


}